package com.bilibili.controller;

import com.bilibili.annocation.CurUser;
import com.bilibili.entity.User;
import com.bilibili.service.PicCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("pic_collections")
public class PicCollectionController {

    @Autowired
    private PicCollectionService picCollectionService;

    /**
     *
     * @param cartoonId 漫画id
     * @param user 用户
     * @return 检查该用户是否收藏过该漫画
     */
    @RequestMapping(value = "{cartoonId}",method = RequestMethod.GET)
    public boolean selectCollectionByIds(@PathVariable("cartoonId") Integer cartoonId, @CurUser User user) {
//        User user1 = new User();
//        user1.setId(2);
        return picCollectionService.selectCollectionByIds(user, cartoonId);
    }

    /**
     *
     * @param cartoonId 漫画id
     * @param user 用户
     * @return 是否添加成功
     */
//    @RequestMapping(method = RequestMethod.POST,params = {"cartoonId"})
    @RequestMapping(method = RequestMethod.GET,params = {"cartoonId"})
    public boolean addCollection(@RequestParam("cartoonId") Integer cartoonId, @CurUser User user) {
//        User user1 = new User();
//        user1.setId(2);
        return picCollectionService.addCollection(user,cartoonId);
    }

    /**
     *
     * @param cartoonId 漫画id
     * @param user 用户
     * @return 是否取消收藏成功
     */
    @RequestMapping(method = RequestMethod.DELETE,params = {"cartoonId"})
    public boolean delCollection(@RequestParam("cartoonId") Integer cartoonId, @CurUser User user) {
//        User user1 = new User();
//        user1.setId(2);
        return picCollectionService.delCollection(user,cartoonId);
    }



}
